<?php
namespace app\admin\controller;
use think\Controller;
use think\Loader;
class Admin extends Controller
{
	//管理员添加
	function add()
	{
		$user = Loader::model('user');
		$exc1=$user->where('user',$_POST['user'])->select();
		$exc2=$user->where('email',$_POST['email'])->select();
		if($exc1){
			$this->error('该账号已存在！');
		}elseif($exc2){
			$this->error('该邮箱已存在！');
		}else{
			$user->data(
				[
					'user'     => $_POST['user'],
					'password' => $_POST['password'],
					'email'    => $_POST['email']
				]);
			$user->save();
		}
	}
	function login()
	{
		$user = Loader::model('user');
		$data=$_POST;
		$password= $user->where('user',$data['user'])->value('password');
		if($password===$_POST['password']){
			session_start();
			$_SESSION['user']=$data['user'];
			$this->success('验证成功！','article/article_list');
		}else{
			$this->error('验证失败！');
		}
		
	}
}